package com.qs.mall.controller;

import com.qs.mall.entity.Product;
import com.qs.mall.service.ProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping(value = "/product")
@RestController
public class ProductController {

    private static final Logger logger = LoggerFactory.getLogger(ProductController.class);

    //获取当前服务ip地址
    @Value("${spring.cloud.client.ip-address}")
    private String ip;

    //获取当前服务端口
    @Value("${server.port}")
    private Integer port;

    @Autowired
    private ProductService productService;


    @GetMapping(value = "/{id}")
    public Product product(@PathVariable Long id) throws InterruptedException {
        logger.info("开始调用商品微服务，获取商品信息");
        logger.info("当前服务ip={}, port={}", ip, port);
        //通过线程阻塞2s，模拟业务执行时间
        Thread.sleep(3000);
        return productService.findById(id);
    }
}
